#ifndef __ICM40607_H
#define __ICM40607_H
#include "stm32f4xx.h"

#define	DEVICE_CONFIG			0X11
#define DRIVE_CONFIG			0X13
#define INT_CONFIG				0X14
#define FIFO_CONFIG				0X16
#define TEMP_DATA1				0X1D
#define TEMP_DATA0 				0X1E
#define ACCEL_DATA_X1			0X1F
#define	ACCEL_DATA_X0			0X20
#define ACCEL_DATA_Y1			0X21
#define	ACCEL_DATA_Y0			0X22
#define ACCEL_DATA_Z1			0X23
#define	ACCEL_DATA_Z0			0X24
#define GYRO_DATA_X1			0X25
#define GYRO_DATA_X0			0X26
#define GYRO_DATA_Y1			0X27
#define GYRO_DATA_Y0			0X28
#define GYRO_DATA_Z1			0X29
#define GYRO_DATA_Z0			0X2A
#define TMST_FSYNCH				0X2B
#define TMST_FSYNCL				0X2C
#define INT_STATUS				0X2D
#define FIFO_COUNTH				0X2E
#define FIFO_COUNTL				0X2F
#define FIFO_DATA					0X30
#define APEX_DATA0 				0X31
#define APEX_DATA1 				0X32
#define APEX_DATA2 				0X33
#define APEX_DATA3 				0X34
#define APEX_DATA4 				0X35
#define APEX_DATA5 				0X36
#define INT_STATUS2				0X37
#define INT_STATUS3				0X38
#define SIGNAL_PATH_RESET 0X4B
#define INTF_CONFIG0			0X4C
#define INTF_CONFIG1			0X4D
#define PWR_MGMT0					0X4E
#define GYRO_CONFIG0			0X4F
#define ACCEL_CONFIG0 		0X50
#define GYRO_CONFIG1			0X51
#define GYRO_ACCEL_CONFIG0 0X52
#define ACCEL_CONFIG1			0X53
#define TMST_CONFIG				0X54
#define APEX_CONFIG0			0X56
#define SMD_CONFIG				0X57
#define FIFO_CONFIG1 			0X5F
#define FIFO_CONFIG2			0X60
#define FIFO_CONFIG3			0X61
#define FSYNC_CONFIG			0X62
#define INT_CONFIG0				0X63
#define INT_CONFIG1				0X64
#define INT_SOURCE0				0X65
#define INT_SOURCE1				0X66
#define INT_SOURCE2				0X68
#define INT_SOURCE3				0X69
#define FIFO_LOST_PKT0		0X6C
#define FIFO_LOST_PKT1		0X6D
#define SELF_TEST_CONFIG	0X70
#define WHO_AM_I					0X75
#define	REG_BANK_SEL			0X76



#define ACCEL_FS_MASK			0xE0  //bit 7:bit5  
#define GYRO_FS_MASK			0xE0	////bit 7:bit5


#define ACCEL_LSB_16G			2048
#define ACCEL_LSB_8G			4096
#define ACCEL_LSB_4G			8192
#define ACCEL_LSB_2G			16384

#define GYRO_LSB_2000 		16.4
#define GYRO_LSB_1000 		32.8
#define GYRO_LSB_500 			65.5
#define GYRO_LSB_250 			131
#define GYRO_LSB_125 			262
#define GYRO_LSB_62_5			524.3
#define GYRO_LSB_31_25 		1048.6
#define GYRO_LSB_15_625		2097.2

#define SPIMSG_READ_ADDR 	0x9D	//0x9d = (TEMP_DATA1 | 0x80)

#define  IMU_CS_ENABLE 				GPIO_ResetBits(SPI_CS_GPIOx,SPI_CS_GPIO_PIN)
#define  IMU_CS_DISABLE 			GPIO_SetBits(SPI_CS_GPIOx,SPI_CS_GPIO_PIN)


typedef struct {
	s16 accel_x;
	s16 accel_y;
	s16 accel_z;
	
	s16 temp;
	
	s16 gyro_x;
	s16 gyro_y;
	s16 gyro_z;
}IMU_SensorRawDataTypeDef;
typedef struct {
	u16 accel_LSB;
	float gyro_LSB;	
}IMU_ConfigTypeDef;

typedef enum
{
	MOTION_IDLE = 0,	//0??
	LOADMAN,		//1??
	AUTOFINDBALANCE,	//2????,????
	OVERANGLE,		//3????,??????
	SELFCHECK,		//4??
	LOCKWARN,		//5??,?????
	ERRSTOP,		//6????
	ASSIST,               	//7??
	SPEEDSTAND,		//8????,????
	SLEEP,                	//9??
	PWMSTOP,		//10??free
} MotionStatus;



u8 IMU_Read_Reg( u8 reg);
void IMU_ReadBytes(u8 *pBuff, u8 ReadAddr, u8 NumbyteToRead);
u8 IMU_Write_Reg(u8 reg, u8 value);
u8 SPI1_ReadWriteByte(u8 Txdata);
void ReadIMU_AllSensors(IMU_SensorRawDataTypeDef *pStr);
void ReadIMU_Config(IMU_ConfigTypeDef *confg);
void SPI_DMASendStart(void);
void SPI_DMASendStop(void);



#endif

/****************************************END OF FLIE icm40607.h**********************************************************/


